package com.autumn.platform.core.support.model.form;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.autumn.platform.core.Utils;

public class FormField implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 4960725733165923305L;
    private String modelId; // 模型ID
    private int fieldSeqno; // 域序号
    private int parentFieldSeqno; // 父域序号
    private int seqno; // 域排序序号
    private String property; // 数据属性
    private String fieldType; // 域类型
    private String fieldTypeParam; // 域类型参数
    private int index; // 所有同字段中的索引

    private String fieldCode; // 域代码/域属性
    private String fieldName; // 域名称/显示文本
    private int columns; // 每行排列数
    private int rowSpan = 1; // 跨行数
    private int colSpan = 1; // 跨列数
    private String defaultValue; // 默认值
    private String minValue; // 最小值
    private String maxValue; // 最大值
    private int labelWidth; // 标签宽度
    private int columnWidth; // 域宽度
    private String chkFormula; // 校验规则
    private String formulaText; // 规则文本
    private String allowBlank; // 是否必输
    private String readOnly; // 是否只读
    private String otherConfig; // 其它配置
    private String memo; // 域说明
    private String dynaFlag; // 动态域标志

    /**
     * 组成树型结构
     */
    private List<FormField> children = null; //直接子节点

    /**
     * 添加一个子节点
     * 
     * @param child
     */
    public void addChild(FormField child) {
        if (null == children) {
            children = new ArrayList<FormField>();
        }
        children.add(child);
    }

    /**
     * 判断是否为叶子节点
     * 
     * @return
     */
    public boolean isLeaf() {
        return null == children || children.isEmpty();
    }

    /**
     * 是否动态域
     */
    public boolean isDynaField() {
        String flag = getDynaFlag();
        if (!Utils.isBlank(flag) && !Utils.string2Boolean(flag)) {
            return false;
        } else {
            return true;
        }
    }

    public String getModelId() {
        return modelId;
    }

    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public int getFieldSeqno() {
        return fieldSeqno;
    }

    public void setFieldSeqno(int fieldSeqno) {
        this.fieldSeqno = fieldSeqno;
    }

    public String getFieldCode() {
        return fieldCode;
    }

    public void setFieldCode(String fieldCode) {
        this.fieldCode = fieldCode;
        this.property = Utils.convertToCamel(fieldCode);
    }

    public String getProperty() {
        if (null == property) {
            synchronized (FormField.class) {
                if (null == property) {
                    property = Utils.convertToCamel(this.fieldCode);
                }
            }
        }
        return property;
    }

    public String getPropertyWithIndex() {
        return getProperty() + getIndex();
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public int getParentFieldSeqno() {
        return parentFieldSeqno;
    }

    public void setParentFieldSeqno(int parentFieldSeqno) {
        this.parentFieldSeqno = parentFieldSeqno;
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public String getFieldTypeParam() {
        return fieldTypeParam;
    }

    public void setFieldTypeParam(String fieldTypeParam) {
        this.fieldTypeParam = fieldTypeParam;
    }

    public String getFieldTypeParam(String key) {
        return this.fieldTypeParam;
    }

    public int getColumns() {
        return columns;
    }

    public void setColumns(int columns) {
        this.columns = columns;
    }

    public int getRowSpan() {
        return rowSpan;
    }

    public void setRowSpan(int rowSpan) {
        this.rowSpan = rowSpan;
    }

    public int getColSpan() {
        return colSpan;
    }

    public void setColSpan(int colSpan) {
        this.colSpan = colSpan;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getMinValue() {
        return minValue;
    }

    public void setMinValue(String minValue) {
        this.minValue = minValue;
    }

    public String getMaxValue() {
        return maxValue;
    }

    public void setMaxValue(String maxValue) {
        this.maxValue = maxValue;
    }

    public int getLabelWidth() {
        return labelWidth;
    }

    public void setLabelWidth(int labelWidth) {
        this.labelWidth = labelWidth;
    }

    public int getColumnWidth() {
        return columnWidth;
    }

    public void setColumnWidth(int columnWidth) {
        this.columnWidth = columnWidth;
    }

    public String getChkFormula() {
        return chkFormula;
    }

    public void setChkFormula(String chkFormula) {
        this.chkFormula = chkFormula;
    }

    public String getFormulaText() {
        return formulaText;
    }

    public void setFormulaText(String formulaText) {
        this.formulaText = formulaText;
    }

    public String getAllowBlank() {
        return allowBlank;
    }

    public void setAllowBlank(String allowBlank) {
        this.allowBlank = allowBlank;
    }

    public String getReadOnly() {
        return readOnly;
    }

    public void setReadOnly(String readOnly) {
        this.readOnly = readOnly;
    }

    public String getOtherConfig() {
        return otherConfig;
    }

    public void setOtherConfig(String otherConfig) {
        this.otherConfig = otherConfig;
    }

    public int getSeqno() {
        return seqno;
    }

    public void setSeqno(int seqno) {
        this.seqno = seqno;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public List<FormField> getChildren() {
        return children;
    }

    public void setChildren(List<FormField> children) {
        this.children = children;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getDynaFlag() {
        return dynaFlag;
    }

    public void setDynaFlag(String dynaFlag) {
        this.dynaFlag = dynaFlag;
    }
}
